package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.MovieBean;
import com.project.mapper.IMovieMapper;
import com.project.service.IMovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class MovieServiceImpl implements IMovieService {
    @Autowired
    private IMovieMapper mapper;

    @Override
    public IPage<MovieBean> cutByItem(Integer pageNO, String name, String storeName, String matches, String rowNum) {
        QueryWrapper<MovieBean> qw = new QueryWrapper<>();
        qw.eq("m_status", "未售出");
        if (name != null && name.length() != 0) {
            qw.like("m_name",name);
        }
        if (storeName != null && storeName.length() != 0) {
            qw.like("m_storeName",storeName);
        }
        if (matches != null && matches.length() != 0) {
            qw.like("m_matches",matches);
        }
        if (rowNum != null && rowNum.length() != 0) {
            qw.like("m_rowNum",rowNum);
        }
        return mapper.selectPage(new Page<>(pageNO,3),qw);
    }

    @Override
    public void buyMovie(MovieBean movie) {
        movie.setStatus("已售出");
        mapper.updateById(movie);
    }

    @Override
    public MovieBean findById(Integer movieId) {
        return mapper.selectById(movieId);
    }
}
